Skip to content

fix(common): create the parent directory in download_model instead of the target file - #2210

Open
DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/download-model-parent-dir
Open

DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/download-model-parent-dir

Conversation

@DZH166

@DZH166 DZH166 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

download_model() builds the destination path and then creates a directory at the file path:

file_path = target_folder / file_name
file_path.mkdir(parents=True, exist_ok=True)     # creates a directory named model.pth
...
with open(file_path, "wb") as f:                 # IsADirectoryError / PermissionError

mkdir succeeds, the following open() always fails (IsADirectoryError on POSIX, PermissionError on Windows) and only requests.HTTPError is handled, so the exception escapes. If the directory already exists from an earlier attempt, the if not file_path.exists() guard silently skips the transfer and returns the directory path instead of weights.

Its only caller, android_ext_env.load_cv_model(), feeds the return value into load_model(), so the GroundingDINO weights can never be downloaded.

before: PermissionError: [Errno 13] Permission denied: '...\weights\model.pth'
after : the streamed payload lands in the returned file

Fix

Create file_path.parent instead of file_path.

Tests

tests/metagpt/utils/test_common.py::test_download_model (streamed response stubbed):

pytest tests/metagpt/utils/test_common.py::test_download_model -q -o addopts="" -o asyncio_mode=auto
# before: 1 failed   after: 1 passed

This branch is waiting to be deployed

1 waiting deployment
unittest — 0db01253 Waiting Nov 18, 2026 by DZH166 via build (3.9) #1776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant